package com.example.pengsiyuan.ppbluetoothle.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.pengsiyuan.ppbluetoothle.DBManager;
import com.example.pengsiyuan.ppbluetoothle.R;
import com.peng.ppscalelibrary.BleManager.Interface.BleBMDJConnectInterface;
import com.peng.ppscalelibrary.BleManager.Manager.BleManager;
import com.peng.ppscalelibrary.BleManager.Model.BleDeviceModel;

import java.util.List;

public class BMDJConnectActivity extends AppCompatActivity {

    BleManager manager;
    private boolean isAutoPush;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.isAutoPush = false;
        setContentView(R.layout.activity_bmdjconnect);
        List<BleDeviceModel> deviceList = DBManager.manager().getDeviceList();
        manager = BleManager.shareInstance(getApplication());
        manager.connectBMDJ(deviceList, new BleBMDJConnectInterface() {
            @Override
            public void connectSuccess() {
                isAutoPush = true;
                Intent intent = new Intent(BMDJConnectActivity.this, BMDJIntroduceActivity.class);
                startActivity(intent);
            }

            @Override
            public void connectFailed() {

            }
        });
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (!isAutoPush){
            manager.dissconnectBMScale();
        }
    }
}
